package com.chaodev.base.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.chaodev.base.dao.MenuAppDao;
import com.chaodev.base.dto.ButtonDTO;
import com.chaodev.base.dto.MenuDTO;
import com.chaodev.base.model.Menu;
import com.chaodev.base.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * vcbase
 *
 * @author 95634
 * @描述
 * @date 2023/5/24 13:52
 **/
@Service("menuApp")
public class MenuAppServiceImpl implements IMenuService {
    @Autowired
    private MenuAppDao menuDao;

    @Override
    public List<Map<String, Object>> getMenuTitle(Map<String, Object> map) {
        return menuDao.getMenuTitle(map);
    }

    @Override
    public List<ButtonDTO> getMenuButton(Map<String, Object> map) {
        return menuDao.getMenuButton(map);
    }

    @Override
    public PageInfo<MenuDTO> menuQuery(Map<String, Object> map) {
        PageHelper.startPage(Integer.parseInt(map.get("P_PAGE").toString()), Integer.parseInt(map.get("P_PAGESIZE").toString()));
        List<MenuDTO> list = menuDao.menuQuery(map);
        return new PageInfo<>(list, Integer.parseInt(map.get("P_PAGESIZE").toString()));
    }


    @Override
    public boolean menuAdd(Menu menu) {
        int result;
        if (null != menu.getMenuId() && !"".equals(menu.getMenuId())) {
            result = menuDao.menuUpd(menu);
        } else {
            result = menuDao.menuAdd(menu);
        }
        return result != 0;
    }


    @Override
    public List<Map<String, Object>> getMenuParentTree(Map<String, Object> map) {
        return menuDao.getMenuParentTree(map);
    }

    @Override
    public List<MenuDTO> getMenuZtree(Map<String, Object> map) {
        return menuDao.getMenuZtree(map);
    }

    @Override
    public List<MenuDTO> getMenuZtreeBtn(Map<String, Object> map) {
        return menuDao.getMenuZtreeBtn(map);
    }

    @Override
    public boolean menuDelete(Menu menu) {
        int result = menuDao.menuDelete(menu);
        return result != 0;
    }

    @Override
    public List<Map<String,Object>> getAppPower(Integer roleCode){
        return menuDao.getAppPower(roleCode);
    }
}
